package com.sys.core.init.mysql.annotation;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by 汤伟杰 on 2017/5/24.
 */
public class SelectMap {


/*
    *//**
     * 1是0否
     * @return List<Map<String,String>>
     *//*
    public static List<Map<String,Object>> getSwitchYN(){
        List<Map<String, Object>> listmap =new ArrayList<Map<String, Object>>();
        for (Yesorno em : Yesorno.values()) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("name", em.getName());
            map.put("value", em.getIndex());
            listmap.add(map);
        }
        return listmap;
    }

    *//**
     * 审批状态
     * @return
     *//*
    public static List<Map<String,Object>> getSelectAS() {
        List<Map<String, Object>> listmap =new ArrayList<Map<String, Object>>();
        for (Approvestatus em : Approvestatus.values()) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("name", em.getName());
            map.put("value", em.getIndex());
            listmap.add(map);
        }
        return listmap;
    }
    *//**
     * 开关
     * @return
     *//*
    public static List<Map<String,Object>> getSwitchOF() {
        List<Map<String, Object>> listmap =new ArrayList<Map<String, Object>>();
        for (Onoroff em : Onoroff.values()) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("name", em.getName());
            map.put("value", em.getIndex());
            listmap.add(map);
        }
        return listmap;
    }*/
    public static List<Map<String,Object>> getListMapByEnum(String classname) throws Exception{
        List<Map<String, Object>> listmap =new ArrayList<Map<String, Object>>();
        Class<?> clazz = Class.forName(classname);
        Method method = clazz.getMethod("values", new Class[]{});
        Method methodname = clazz.getMethod("getName", new Class[]{});
        Method methodIndex = clazz.getMethod("getIndex", new Class[]{});
        Object[] ss = (Object[]) method.invoke(clazz);
        for (int i = 0; i < ss.length; i++) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("name", methodname.invoke(ss[i]));
            map.put("value", methodIndex.invoke(ss[i]));
            listmap.add(map);
        }
        return listmap;
    }
}
